#pragma once

#include <mutex>

namespace bin {
template <class T> 
class Singleton
{
  protected:
    Singleton() {}

  public:
    static T* GetInstance()
    {
        static T*         ins;
        static std::mutex mx;
        if (ins == nullptr) {
            std::unique_lock<std::mutex> lock(mx);
            if (ins == nullptr) {
                ins = new (std::nothrow) T;
            }
        }

        return ins;
    }

    Singleton(const Singleton&) = delete; // 关闭拷贝构造

    Singleton(const Singleton&&) = delete; // 关闭右值拷贝构造

    Singleton& operator=(const Singleton&) = delete; // 关闭赋值重载

    virtual ~Singleton() {}
};
} // namespace bin